<?php

//送礼记录
namespace App\Http\Controllers\Admin;

use App\Exceptions\BasicException;
use App\Http\Controllers\BaseController;
use App\Response\Response;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class GiveGiftController extends BaseController
{
    /**
     * @api {Get} /giveGift/export/excel 送礼记录导出
     * @apiGroup 送礼记录
     *
     * @apiParam {string} start_time 开始时间 非必传
     * @apiParam {string} end_time 结束时间 非必传
     * @apiParam {int} room_code 房间编号 非必传
     * @apiParam {int} user_code 用户编号 非必传
     * @apiParam {int} mobile 手机号 非必传
     * @apiParam {int} gift_type 礼物类型id 非必传 -1表示不搜索
     *
     * @apiSuccessExample {json} Response-Example
     *

     *
     */
    public function export(Request $request)
    {
        set_time_limit(0);
        ini_set('memory_limit', '2048M');
        $v = app('validator')->make(
            $request->all(),
            [
                'start_time' => 'date',
                'end_time' => 'date',
                'room_code' => 'integer|gt:0',
                'user_code' => 'integer|gt:0',
                'mobile' => 'integer|gt:0',
                'gift_type' => 'integer',
            ]
        );
        if ($v->fails()) {
            throw new BasicException(10010, getValidateMessage($v->messages()));
        }

        $params = $request->input();
        $result = app('repo_give_gift')->export($params);

        return Response::sendData($result);
    }

    /**
     * @api {Get} /giveGift/list 送礼记录列表
     * @apiGroup 送礼记录
     *
     * @apiParam {string} start_time 开始时间 非必传
     * @apiParam {string} end_time 结束时间 非必传
     * @apiParam {int} room_code 房间编号 非必传
     * @apiParam {int} user_code 用户编号 非必传
     * @apiParam {int} mobile 手机号 非必传
     * @apiParam {int} page 页码 非必传（默认1）
     * @apiParam {int} page_size 页码尺寸 非必传（默认20）
     * @apiParam {int} gift_type 礼物类型id 非必传 -1表示不搜索
     *
     * @apiSuccessExample {json} Response-Example
     *
    {
    "code": 200,
    "data": {
    "list": [
    {
    "id": 23388,
    "user_id": 301455,
    "org_gift_id": 702,
    "gift_id": 702,
    "number": 1,
    "gift_user": 301933,
    "room_id": 202,
    "pit_number": 1,
    "add_time": 1646806707,
    "org_total_price": "520.00",
    "total_price": "520.00",
    "type": 0,
    "coin": "0.00",
    "user_code": 5304152,
    "nickname": "小冰语99",
    "mobile": "13211111111",
    "gift_name": "香水",
    "gift_type": 1,
    "room_code": 5202291,
    "room_name": "出来聚聚"
    }
    ],
    "current_page": 1,
    "last_page": 1170,
    "total": 23387
    },
    "message": ""
    }
     *
     */
    public function list(Request $request)
    {
        $v = app('validator')->make(
            $request->all(),
            [
                'start_time' => 'date',
                'end_time' => 'date',
                'room_code' => 'integer|gt:0',
                'user_code' => 'integer|gt:0',
                'mobile' => 'integer|gt:0',
                'page' => 'integer|gt:0',
                'page_size' => 'integer|gt:0',
                'gift_type' => 'integer',
            ]
        );
        if ($v->fails()) {
            throw new BasicException(10010, getValidateMessage($v->messages()));
        }

        $params = $request->input();
        $result = app('repo_give_gift')->list($params);

        return Response::sendData($result);
    }

    //获取礼物分类下拉菜单
    public function getGiftType()
    {
        $result = app('repo_give_gift')->getGiftType();

        return Response::sendData($result);
    }
}
